Skip to content

Commit c97be5d

Browse files
committed
Add tests for Source Phase Imports
1 parent b628e4b commit c97be5d

File tree

174 files changed

+6976
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

174 files changed

+6976
-0
lines changed

INTERPRETING.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ properties of the global scope prior to test execution.
107107
- **`sleep`** - a function that takes a millisecond argument and
108108
sleeps the execution for approximately that duration.
109109
- **`monotonicNow`** - a function that returns a value that conforms to [`DOMHighResTimeStamp`][] and is produced in such a way that its semantics conform to **[Monotonic Clock][]**.
110+
- **`AbstractModuleSource`** - a reference to the %AbstractModuleSource% constructor which does not appear as a property of the global object.
110111

111112
In addition, consumers may choose to override any of [the functions defined by test harness files](https://github.com/tc39/test262/blob/HEAD/CONTRIBUTING.md#test-environment) as they see fit. See [the documentation on handling errors and negative test cases](https://github.com/tc39/test262/blob/HEAD/CONTRIBUTING.md#handling-errors-and-negative-test-cases) for a useful example of this.
112113

features.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,10 @@ promise-with-resolvers
105105
# https://github.com/tc39/proposal-set-methods
106106
set-methods
107107

108+
# Source Phase Imports
109+
## https://github.com/tc39/proposal-source-phase-imports
110+
source-phase-imports
111+
108112
## Standard language features
109113
#
110114
# Language features that have been included in a published version of the
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Copyright (C) 2024 Chengzhong Wu. All rights reserved.
2+
// Copyright (C) 2018 Rick Waldron. All rights reserved.
3+
// Copyright (C) 2018 the V8 project authors. All rights reserved.
4+
// This code is governed by the BSD license found in the LICENSE file.
5+
/*---
6+
desc: It's a SyntaxError if AssignmentExpression is omitted
7+
template: syntax/invalid
8+
info: |
9+
ImportCall[Yield, Await] :
10+
import . source ( AssignmentExpression[+In, ?Yield, ?Await] )
11+
features: [source-phase-imports]
12+
---*/
13+
//- import
14+
import.source()
15+
//- teardown
16+
/* The params region intentionally empty */
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// Copyright (C) 2024 Chengzhong Wu. All rights reserved.
2+
// Copyright (C) 2018 Rick Waldron. All rights reserved.
3+
// Copyright (C) 2018 the V8 project authors. All rights reserved.
4+
// This code is governed by the BSD license found in the LICENSE file.
5+
/*---
6+
desc: Calling import.source('')
7+
template: syntax/valid
8+
features: [source-phase-imports]
9+
---*/
10+
11+
//- import
12+
import.source('')
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright (C) 2024 Chengzhong Wu. All rights reserved.
2+
// Copyright (C) 2018 Leo Balter. All rights reserved.
3+
// This code is governed by the BSD license found in the LICENSE file.
4+
/*---
5+
desc: ImportCall is a CallExpression, it can't be preceded by the new keyword
6+
template: syntax/invalid
7+
info: |
8+
CallExpression:
9+
ImportCall
10+
11+
ImportCall :
12+
import . source ( AssignmentExpression[+In, ?Yield, ?Await] )
13+
14+
features: [source-phase-imports]
15+
---*/
16+
17+
//- import
18+
new import.source('')
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Copyright (C) 2024 Chengzhong Wu. All rights reserved.
2+
// Copyright (C) 2018 Leo Balter. All rights reserved.
3+
// This code is governed by the BSD license found in the LICENSE file.
4+
/*---
5+
desc: ImportCall is not extensible - no rest parameter
6+
template: syntax/invalid
7+
info: |
8+
ImportCall :
9+
import . source ( AssignmentExpression[+In, ?Yield] )
10+
11+
Forbidden Extensions
12+
13+
- ImportCall must not be extended.
14+
15+
This production doesn't allow the following production from ArgumentsList:
16+
17+
... AssignmentExpression
18+
---*/
19+
20+
//- import
21+
import.source(...[''])
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Copyright (C) 2024 Chengzhong Wu. All rights reserved.
2+
// Copyright (C) 2018 Leo Balter. All rights reserved.
3+
// This code is governed by the BSD license found in the LICENSE file.
4+
/*---
5+
desc: import.source() can be used in script code
6+
template: syntax/valid
7+
features: [source-phase-imports]
8+
---*/
9+
10+
//- setup
11+
// This is still valid in script code, and should not be valid for module code
12+
// https://tc39.github.io/ecma262/#sec-scripts-static-semantics-lexicallydeclarednames
13+
var smoosh; function smoosh() {}
14+
15+
//- import
16+
import.source('')
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// Copyright (C) 2024 Chengzhong Wu. All rights reserved.
2+
// This code is governed by the BSD license found in the LICENSE file.
3+
/*---
4+
desc: >
5+
GetModuleSource of SourceTextModule always returns an abrupt completion.
6+
esid: sec-moduleevaluation
7+
info: |
8+
16.2.1.7.2 GetModuleSource ( )
9+
Source Text Module Record provides a GetModuleSource implementation that always returns an abrupt completion indicating that a source phase import is not available.
10+
1. Throw a ReferenceError exception.
11+
12+
Import Calls
13+
14+
Runtime Semantics: Evaluation
15+
16+
ImportCall : import . source ( AssignmentExpression )
17+
1. Return ? EvaluateImportCall(AssignmentExpression, source).
18+
19+
13.3.10.1.1 EvaluateImportCall ( specifierExpression, phase )
20+
1. Let referrer be GetActiveScriptOrModule().
21+
2. If referrer is null, set referrer to the current Realm Record.
22+
3. Let specifierRef be ? Evaluation of specifierExpression.
23+
4. Let specifier be ? GetValue(specifierRef).
24+
5. Let promiseCapability be ! NewPromiseCapability(%Promise%).
25+
6. Let specifierString be Completion(ToString(specifier)).
26+
7. IfAbruptRejectPromise(specifierString, promiseCapability).
27+
8. Let moduleRequest be a new ModuleRequest Record { [[Specifier]]: specifierString, [[Phase]]: phase }.
28+
9. Perform HostLoadImportedModule(referrer, moduleRequest, empty, promiseCapability).
29+
10. Return promiseCapability.[[Promise]].
30+
31+
template: catch
32+
features: [source-phase-imports]
33+
---*/
34+
35+
//- import
36+
import.source('./empty_FIXTURE.js')
37+
//- body
38+
assert.sameValue(error.name, 'ReferenceError');
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// Copyright (C) 2024 Chengzhong Wu. All rights reserved.
2+
// Copyright (C) 2018 Rick Waldron. All rights reserved.
3+
// Copyright (C) 2018 the V8 project authors. All rights reserved.
4+
// This code is governed by the BSD license found in the LICENSE file.
5+
/*---
6+
desc: >
7+
Abrupt from ToString(specifier) rejects the promise
8+
esid: sec-moduleevaluation
9+
info: |
10+
Import Calls
11+
12+
Runtime Semantics: Evaluation
13+
14+
ImportCall : import . source ( AssignmentExpression )
15+
1. Return ? EvaluateImportCall(AssignmentExpression, source).
16+
17+
13.3.10.1.1 EvaluateImportCall ( specifierExpression, phase )
18+
1. Let referrer be GetActiveScriptOrModule().
19+
2. If referrer is null, set referrer to the current Realm Record.
20+
3. Let specifierRef be ? Evaluation of specifierExpression.
21+
4. Let specifier be ? GetValue(specifierRef).
22+
5. Let promiseCapability be ! NewPromiseCapability(%Promise%).
23+
6. Let specifierString be Completion(ToString(specifier)).
24+
7. IfAbruptRejectPromise(specifierString, promiseCapability).
25+
8. Let moduleRequest be a new ModuleRequest Record { [[Specifier]]: specifierString, [[Phase]]: phase }.
26+
9. Perform HostLoadImportedModule(referrer, moduleRequest, empty, promiseCapability).
27+
10. Return promiseCapability.[[Promise]].
28+
template: catch
29+
features: [source-phase-imports]
30+
---*/
31+
32+
//- setup
33+
const obj = {
34+
toString() {
35+
throw 'custom error';
36+
}
37+
};
38+
39+
//- import
40+
import.source(obj)
41+
//- body
42+
assert.sameValue(error, 'custom error');
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
// Copyright (C) 2024 Chengzhong Wu. All rights reserved.
2+
// Copyright (C) 2018 Rick Waldron. All rights reserved.
3+
// Copyright (C) 2018 the V8 project authors. All rights reserved.
4+
// This code is governed by the BSD license found in the LICENSE file.
5+
/*---
6+
desc: >
7+
ToString value of specifier
8+
esid: sec-moduleevaluation
9+
info: |
10+
Import Calls
11+
12+
Runtime Semantics: Evaluation
13+
14+
ImportCall : import . source ( AssignmentExpression )
15+
1. Return ? EvaluateImportCall(AssignmentExpression, source).
16+
17+
13.3.10.1.1 EvaluateImportCall ( specifierExpression, phase )
18+
1. Let referrer be GetActiveScriptOrModule().
19+
2. If referrer is null, set referrer to the current Realm Record.
20+
3. Let specifierRef be ? Evaluation of specifierExpression.
21+
4. Let specifier be ? GetValue(specifierRef).
22+
5. Let promiseCapability be ! NewPromiseCapability(%Promise%).
23+
6. Let specifierString be Completion(ToString(specifier)).
24+
7. IfAbruptRejectPromise(specifierString, promiseCapability).
25+
8. Let moduleRequest be a new ModuleRequest Record { [[Specifier]]: specifierString, [[Phase]]: phase }.
26+
9. Perform HostLoadImportedModule(referrer, moduleRequest, empty, promiseCapability).
27+
10. Return promiseCapability.[[Promise]].
28+
29+
16.2.1.7.2 GetModuleSource ( )
30+
Source Text Module Record provides a GetModuleSource implementation that always returns an abrupt completion indicating that a source phase import is not available.
31+
1. Throw a ReferenceError exception.
32+
33+
template: catch
34+
features: [source-phase-imports]
35+
---*/
36+
37+
//- setup
38+
// The following case is equivalent of the call of:
39+
// import.source('./empty_FIXTURE.js')
40+
41+
const obj = {
42+
toString() {
43+
return './empty_FIXTURE.js';
44+
}
45+
};
46+
47+
//- import
48+
import.source(obj)
49+
//- body
50+
assert.sameValue(error.name, 'ReferenceError');
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// Copyright (C) 2024 Chengzhong Wu. All rights reserved.
2+
// This code is governed by the BSD license found in the LICENSE file.
3+
4+
// empty code
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
// This file was procedurally generated from the following sources:
2+
// - src/dynamic-import/import-source-source-text-module.case
3+
// - src/dynamic-import/catch/nested-arrow.template
4+
/*---
5+
description: GetModuleSource of SourceTextModule always returns an abrupt completion. (nested arrow)
6+
esid: sec-import-call-runtime-semantics-evaluation
7+
features: [source-phase-imports, dynamic-import]
8+
flags: [generated, async]
9+
info: |
10+
ImportCall :
11+
import( AssignmentExpression )
12+
13+
1. Let referencingScriptOrModule be ! GetActiveScriptOrModule().
14+
2. Assert: referencingScriptOrModule is a Script Record or Module Record (i.e. is not null).
15+
3. Let argRef be the result of evaluating AssignmentExpression.
16+
4. Let specifier be ? GetValue(argRef).
17+
5. Let promiseCapability be ! NewPromiseCapability(%Promise%).
18+
6. Let specifierString be ToString(specifier).
19+
7. IfAbruptRejectPromise(specifierString, promiseCapability).
20+
8. Perform ! HostImportModuleDynamically(referencingScriptOrModule, specifierString, promiseCapability).
21+
9. Return promiseCapability.[[Promise]].
22+
23+
24+
16.2.1.7.2 GetModuleSource ( )
25+
Source Text Module Record provides a GetModuleSource implementation that always returns an abrupt completion indicating that a source phase import is not available.
26+
1. Throw a ReferenceError exception.
27+
28+
Import Calls
29+
30+
Runtime Semantics: Evaluation
31+
32+
ImportCall : import . source ( AssignmentExpression )
33+
1. Return ? EvaluateImportCall(AssignmentExpression, source).
34+
35+
13.3.10.1.1 EvaluateImportCall ( specifierExpression, phase )
36+
1. Let referrer be GetActiveScriptOrModule().
37+
2. If referrer is null, set referrer to the current Realm Record.
38+
3. Let specifierRef be ? Evaluation of specifierExpression.
39+
4. Let specifier be ? GetValue(specifierRef).
40+
5. Let promiseCapability be ! NewPromiseCapability(%Promise%).
41+
6. Let specifierString be Completion(ToString(specifier)).
42+
7. IfAbruptRejectPromise(specifierString, promiseCapability).
43+
8. Let moduleRequest be a new ModuleRequest Record { [[Specifier]]: specifierString, [[Phase]]: phase }.
44+
9. Perform HostLoadImportedModule(referrer, moduleRequest, empty, promiseCapability).
45+
10. Return promiseCapability.[[Promise]].
46+
47+
---*/
48+
49+
let f = () => {
50+
import.source('./empty_FIXTURE.js').catch(error => {
51+
52+
assert.sameValue(error.name, 'ReferenceError');
53+
54+
}).then($DONE, $DONE);
55+
};
56+
57+
f();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
// This file was procedurally generated from the following sources:
2+
// - src/dynamic-import/import-source-specifier-tostring-abrupt-rejects.case
3+
// - src/dynamic-import/catch/nested-arrow.template
4+
/*---
5+
description: Abrupt from ToString(specifier) rejects the promise (nested arrow)
6+
esid: sec-import-call-runtime-semantics-evaluation
7+
features: [source-phase-imports, dynamic-import]
8+
flags: [generated, async]
9+
info: |
10+
ImportCall :
11+
import( AssignmentExpression )
12+
13+
1. Let referencingScriptOrModule be ! GetActiveScriptOrModule().
14+
2. Assert: referencingScriptOrModule is a Script Record or Module Record (i.e. is not null).
15+
3. Let argRef be the result of evaluating AssignmentExpression.
16+
4. Let specifier be ? GetValue(argRef).
17+
5. Let promiseCapability be ! NewPromiseCapability(%Promise%).
18+
6. Let specifierString be ToString(specifier).
19+
7. IfAbruptRejectPromise(specifierString, promiseCapability).
20+
8. Perform ! HostImportModuleDynamically(referencingScriptOrModule, specifierString, promiseCapability).
21+
9. Return promiseCapability.[[Promise]].
22+
23+
24+
Import Calls
25+
26+
Runtime Semantics: Evaluation
27+
28+
ImportCall : import . source ( AssignmentExpression )
29+
1. Return ? EvaluateImportCall(AssignmentExpression, source).
30+
31+
13.3.10.1.1 EvaluateImportCall ( specifierExpression, phase )
32+
1. Let referrer be GetActiveScriptOrModule().
33+
2. If referrer is null, set referrer to the current Realm Record.
34+
3. Let specifierRef be ? Evaluation of specifierExpression.
35+
4. Let specifier be ? GetValue(specifierRef).
36+
5. Let promiseCapability be ! NewPromiseCapability(%Promise%).
37+
6. Let specifierString be Completion(ToString(specifier)).
38+
7. IfAbruptRejectPromise(specifierString, promiseCapability).
39+
8. Let moduleRequest be a new ModuleRequest Record { [[Specifier]]: specifierString, [[Phase]]: phase }.
40+
9. Perform HostLoadImportedModule(referrer, moduleRequest, empty, promiseCapability).
41+
10. Return promiseCapability.[[Promise]].
42+
43+
---*/
44+
const obj = {
45+
toString() {
46+
throw 'custom error';
47+
}
48+
};
49+
50+
51+
let f = () => {
52+
import.source(obj).catch(error => {
53+
54+
assert.sameValue(error, 'custom error');
55+
56+
}).then($DONE, $DONE);
57+
};
58+
59+
f();

0 commit comments

Comments
 (0)